<?php


namespace app\api\controller;


use app\api\model\BannerModel;
use app\api\model\GoodsModel;
use app\api\model\UserInfoModel;
use app\api\model\UserModel;
use app\api\validate\UserInfoValidate;
use think\Db;
use think\Exception;

class Index extends ApiBase
{

    /**
     *
     * 轮播图列表
     */
    public function bannerList(){

        $data = BannerModel::bannerList();
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 提交表单信息
     */
    public function userInfoAdd(UserInfoValidate $request){

        $params = $this->request->post();
        $params['user_id'] = $this->id;
        if (!$request->scene('userInfoAdd')->check($params)){

            $this->fail($request->getError());
        }
        $info = UserInfoModel::where(['user_id'=>3])->find();
        if ($info && $info['update_at'] > 0){

            $this->fail('用户只能修改一次！');
        }
        $res = UserInfoModel::userInfoAdd($params);

        if ($res){

            $this->successful('提交成功');
        }else{

            $this->fail('提交失败');
        }

    }

    /**
     *
     * 表单信息信息
     */
    public function userInfo(){

        $data = UserInfoModel::userInfo($this->id);
        $this->successful('查询成功',$data);
    }

}